import json
class COutInfo:
    def __init__(self,outindex,txout):
        #索引
        self.__outindex = outindex
        #交易输出
        self.__txout= txout
    @property
    def txout(self):
        return self.__txout

    @txout.setter
    def txout(self,value):
        self.txout =value
    
    @property
    def outindex(self):
        return self.__outindex

    @outindex.setter
    def outindex(self,value):
        self.__outindex =value


    #Object——>jsonStr
    def serializeToJsonStr(self):
        sttr=json.dumps(self, default=lambda obj: obj.__dict__)
        return sttr.replace("_COutInfo__","")

    #jsonStr——> Object
    @classmethod
    def deserializeFromJsonStr(cls,jsonStrobjectdata):
        d = json.loads(jsonStrobjectdata)
        #print(d['txins'])
        return  cls(d['outindex'],d['txout'])
       
    
    #Object——>Python Object
    def serializeToPyObject(self):
        return json.loads(self.serializeToJsonStr())
    
    #Python Object——>Object
    @classmethod
    def deserializeFromPyObject(cls,pyObject):
       return cls.deserializeFromJsonStr(json.dumps(pyObject))

class CUTx:
    def __init__(self,txhash="",blkhash="",timestamp='0',unSpendOuts=[],txtype=1):
        #交易hash
        self.__txhash =txhash
        self.__txtype=txtype
        self.__blkhash =blkhash
        self.__unSpendOuts=unSpendOuts
        self.__timestamp=timestamp
    @property
    def txtype(self):
        return self.__txtype
    
    
    @property
    def timestamp(self):
        return self.__timestamp

    @timestamp.setter
    def timestamp(self,value):
        self.__timestamp =value
    
    @property
    def txhash(self):
        return self.__txhash

    @txhash.setter
    def txhash(self,value):
        self.__txhash =value

    @property
    def blkhash(self):
        return self.__blkhash

    @blkhash.setter
    def blkhash(self,value):
        self.__blkhash =value
    
    @property
    def unSpendOuts(self):
        return self.__unSpendOuts

    @unSpendOuts.setter
    def unSpendOuts(self,value):
        self.__unSpendOuts =value


   #Object——>jsonStr
    def serializeToJsonStr(self):
        sttr=json.dumps(self, default=lambda obj: obj.__dict__)
        return sttr.replace("_CUTx__","").replace("_CTxOut__","").replace("_CScriptPubKey__","")

    #jsonStr——> Object
    @classmethod
    def deserializeFromJsonStr(cls,jsonStrobjectdata):
        d = json.loads(jsonStrobjectdata)
        #print(d['txins'])
        return  cls(d['txhash'],d['blkhash'],d['timestamp'],d['unSpendOuts'],d['txtype'])
       
    #Object——>Python Object
    def serializeToPyObject(self):
        return json.loads(self.serializeToJsonStr())
    
    #Python Object——>Object
    @classmethod
    def deserializeFromPyObject(cls,pyObject):
       return cls.deserializeFromJsonStr(json.dumps(pyObject))